import { LoadingPlugin } from 'tdesign-vue-next';
import { Ref, ref } from 'vue';

export const useLoading = (domRef: Ref) => {
  const loadingAttachInstance = ref<any>();

  const loadingStart = () => {
    loadingAttachInstance.value = LoadingPlugin({
      attach: () => domRef.value,
      showOverlay: true,
      size: '20px',
    });
  };

  const loadingEnd = () => {
    loadingAttachInstance.value.hide();
  };

  return { loadingStart, loadingEnd };
};
